using System;
using System.Transactions;
using Budgeteer.Services.Common;
using Budgeteer.Services.DataProviders;
using Budgeteer.Services.Domain;
using Xunit;

namespace Test.UnitTests.Budgeteer.Services.DataProviders
{
    public class ChargeDataProviderFacts
    {
        public class InsertTransactionData : IDisposable
        {
            readonly TransactionScope transaction;

            public InsertTransactionData()
            {
                transaction = BaseDataProvider.CreateTransactionScope();
            }

            [Fact]
            public void ShouldInsertTransactionData()
            {
                ChargeDataProvider provider = new ChargeDataProvider(Config.ConnectionString);

                ChargeDto charge =
                    new ChargeDto
                        {
                            Time = DateTime.Parse("08/12/2008"),
                            Name = "STARBUCKS USA MIAMI FL",
                            Amount = 7.3M,
                            Category = "COFFEE",
                            Account = "Visa"
                        };

                provider.InsertTransactionData(charge);

                ChargeDto actual = provider.GetChargeData(charge.Id);

                Assert.Equal(charge.Id,actual.Id);
                Assert.Equal(charge.Time,actual.Time);
                Assert.Equal(charge.Name,actual.Name);
                Assert.Equal(charge.Amount,actual.Amount);
                Assert.Equal(charge.Category,actual.Category);
                Assert.Equal(charge.Account,actual.Account);
            }

            public void Dispose()
            {
                transaction.Dispose();
            }
        }
    }

    public class StubChargeDataProvider : ChargeDataProvider
    {
        public bool InsertTransactionData_Called;
        public ChargeDto InsertTransactionData_Charge;

        public StubChargeDataProvider()
            : base("")
        {
        }

        public override void InsertTransactionData(ChargeDto charge)
        {
            InsertTransactionData_Called = true;
            InsertTransactionData_Charge = charge;
        }
    }
}